/*
Sequences: Vec, VecDeque, linked_list
Maps: HashMap, BTreeMap
Sets: HashSet, BTreeSet
Misc: BinaryHeap
*/
use std::collections::VecDeque;

#[test]
fn vec() {
    let vec = vec![1, 2, 3, 4];
    for x in vec.iter() {
        println!("vec contained {x:?}");
    }

    // Iter_mut 提供了与 iter 相同顺序的可变引用迭代器。这对于改变集合中的所有内容非常有用。
    let mut vec = vec![1, 2, 3, 4];
    for x in vec.iter_mut() {
        *x += 1;
    }
    println!("{:?}", vec);

    let mut vec1 = vec![1, 2, 3, 4];
    let vec2 = vec![10, 20, 30, 40];
    vec1.extend(vec2); // 擴展
    println!("{:?}", vec1);
    let vec = [1, 2, 3, 4];
    let mut buf: VecDeque<_> = vec.into_iter().collect(); // 双端队列
    buf.push_back(10);
    buf.push_front(20);
    println!("{:?}", buf);
}

// === NEW IMPLEMENTATION START ===
// CRITICAL: Vec 与 VecDeque 更完整示例，展示常用方法和迭代策略。
#[allow(dead_code)]
pub fn stdx_examples_vec() {
    // CRITICAL: Vec 基本创建和迭代
    let mut v = Vec::new();
    v.push(1);
    v.push(2);
    v.push(3);

    for (i, val) in v.iter().enumerate() {
        // AUTO_COMMENT: enumerate 提供索引与值
        let _ = (i, val);
    }

    // CRITICAL: iter_mut 提供可变访问
    for val in v.iter_mut() {
        *val += 10;
    }

    // CRITICAL: extend 和 append 示范
    let mut v1 = vec![1, 2];
    let v2 = vec![3, 4];
    v1.extend(v2);

    use std::collections::VecDeque;
    let mut dq: VecDeque<i32> = VecDeque::from([1, 2, 3]);
    dq.push_back(4);
    dq.push_front(0);
    let _popped = dq.pop_back();

    // AUTO_COMMENT: 避免未使用警告
    let _ = (v, v1, dq);
}
// === NEW IMPLEMENTATION END ===
